package com.dragon.www.smarthome.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.dragon.www.smarthome.entity.Device;
import com.dragon.www.smarthome.entity.InitializeAirValueInfo;
import com.dragon.www.smarthome.entity.InitializeRelayValueInfo;

import java.util.List;

/**
 * Created by Administrator on 2015/9/9 16:43.
 * Author: Songxy
 * Email: thinkdata@163.com
 */
public abstract class AppArrayAdapter<T, M extends AppHolder> extends BaseAdapter {

    private int resourceId;
    private Class<M> tClass;
    List<Device> devices;
    int box1;
    int box2;
    InitializeRelayValueInfo[] deviceInfo;
    InitializeAirValueInfo[] deviceInfo1;
    List<int[]> lamppower;
    Context context;
    AppHolder holder = null;

    public AppArrayAdapter(Context context) {
        this.context = context;
    }

    public AppArrayAdapter(Context context, int resourceId, Class clzz) {
        this(context);
        this.resourceId = resourceId;
        this.tClass = clzz;
    }

    public void initData(){

    }

    public void setlamppower(List<int[]> devices) {
        this.lamppower = devices;
    }

    public List<int[]> getlamppower(){
        return lamppower;
    }

    public List<Device> getData(){
        return devices;
    }

    public void setData(List<Device> devices) {
        this.devices = devices;
        initData();
        notifyDataSetChanged();
        if (devices.size() != 0 ){
            box1 = Integer.parseInt(devices.get(0).getequipNo().split("-")[0]);

            for (Device x : devices) {

                if (Integer.parseInt(x.getequipNo().split("-")[0]) != box1){
                    box2 = Integer.parseInt(x.getequipNo().split("-")[0]);
                }
            }
        }
    }

    public void setValue(InitializeRelayValueInfo[] deviceInfo) {
        this.deviceInfo = deviceInfo;
        initData();
        notifyDataSetChanged();
    }

    public void setValue(InitializeAirValueInfo[] deviceInfo) {
        this.deviceInfo1 = deviceInfo;
        initData();
        notifyDataSetChanged();
    }

    @Override
    public int getCount(){
        return devices.size();
    }

    @Override
    public Object getItem(int position){
        return devices.get(position);
    }

    @Override
    public long getItemId(int position){
        return position;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        //存放临时对象
        view = bindHolder(view, parent, position);
        return view;
    }

    /**
     * 临时对象绑定
     * @param view
     * @param parent
     * @param position
     */
    public abstract View bindHolder(View view, ViewGroup parent, int position) ;
}
